package frank.zou.test.dbunit.base;

import java.sql.Connection;
import java.sql.DriverManager;
import org.dbunit.database.DatabaseConnection;
import org.dbunit.database.IDatabaseConnection;

/**
 * 
 * 
 * @author <a href="mailto:sunjin_sunny@hotmail.com">sunny</a>
 * @version
 * @since 2008-2-25
 * 
 */
public abstract class BasicDBUnitHelper {

	public static final String FILE_NAME = DBParameterConstant.FILE_NAME;

	public static final String DB_DRIVER = DBParameterConstant.DB_DRIVER;

	public static final String DB_URL = DBParameterConstant.DB_URL;

	public static final String DB_USER = DBParameterConstant.DB_USER;

	public static final String DB_PASSWORD = DBParameterConstant.DB_PASSWORD;

	protected abstract void init(String fileName);

	protected abstract String getProperty(String name);

	public String getDBDriver() {
		return getProperty(DB_DRIVER);
	}

	public String getDBUrl() {
		return getProperty(DB_URL);
	}

	public String getUser() {
		return getProperty(DB_USER);
	}

	public String getPassword() {
		return getProperty(DB_PASSWORD);
	}

	public IDatabaseConnection getConnnection() throws Exception {
		Class.forName(getDBDriver());
		Connection jdbcConnection = DriverManager.getConnection(getDBUrl(),
				getUser(), getPassword());
		return new DatabaseConnection(jdbcConnection);
	}

	public void closeConnection(IDatabaseConnection connection)
			throws Exception {
		connection.close();
	}
}
